import { _decorator, Component, Node } from 'cc';
import { StatisticsBase } from './StatisticsBase';
import engine from '../../Engine';
import { CCGlobal, UrseStat } from '../util/CCGlobal';
import { CCComFun } from '../util/CCComFun';
const { ccclass, property } = _decorator;

@ccclass('GameStatistics')
export class GameStatistics extends StatisticsBase {


    /**游戏统计初始化 */
    public GameStatisticsInit() {
        if (engine.cc_debug) { return };
        this.launchOptionsSyncInit();
        this.userLogin();
        this.conversion();
    }

    /**启动参数初始化 */
    protected launchOptionsSyncInit() {
        this.launchOptionsSync = CCGlobal.API.getLaunchOptionsSync();
        this.debugLogUrl({
            launchOptionsSync: JSON.stringify(this.launchOptionsSync)
        })
        CCComFun.StatLog("launchOptionsSync:", JSON.stringify(this.launchOptionsSync))
    }

    /**用户登录 */
    public userLogin() {
        CCGlobal.API.login({
            force: false,
            success: (res) => {
                this.getOpenid(res);
                CCComFun.StatLog(`login 调用成功${res}`);
                this.debugLogUrl({
                    loginConfig: JSON.stringify(res)
                })
            },
            fail: (err) => {
                CCComFun.StatLog(`login 调用失败`, err);
            },
        })
    }


    /**激励视频奖励 */
    public rewardVideo() {
        let data = {
            adUnitld: CCGlobal.Config.videoId,
        }
        CCGlobal.API.request({
            URL: CCComFun.statConfig.rewardVideo,
            method: "POST",
            data: JSON.stringify(data)
        })
    }

    /**归因注册激活 */
    private conversion() {
        let data = {
            event_type: "active",
            context: {
                ad: {
                    callback: this.launchOptionsSync.query.clickid
                },
            },
            timestamp: this.millisecondTimestamp(),
        }
        CCComFun.StatLog(`conversion 归因注册激活`, JSON.stringify(data));
        CCGlobal.API.request({
            url: CCComFun.statConfig.conversion,
            method: "POST",
            data: JSON.stringify(data),
            success: (code) => {
                this.debugLogUrl({
                    conversion: this.stringify(code),
                })
                CCComFun.StatLog(`conversionSuccess : ${this.stringify(code)}`)
            },
            fail: (err) => {
                CCComFun.StatLog(`conversionErr : ${JSON.stringify(err)}`);
            }
        })
    }




    /**游戏统计 */
    public gameStat(code) {

        let data = {
            ...this.basicAB,
            ...code,
        }

        CCComFun.StatLog(`GameStat : ${this.stringify(data)}`)
        this.buildUrl(data);
    }










}

const temp = { "path": "", "query": { "ad_params": "%7B%22cid%22%3A1805636051451008%2C%22ad_id%22%3A1805636051446873%2C%22log_extra%22%3A%7B%22ad_price%22%3A%22ZqN2hP_xMUVmo3aE__ExRQ9CYmFxvjRMxfg89Q%22%2C%22ad_show_type%22%3A0%2C%22bdid%22%3A%2295e27d21c9264aea98d7a184c1ebff6fb2e63ac084b66fd31f3d60235d3a059d%22%2C%22card_id%22%3A0%2C%22clickid%22%3A%22EID5wrv2xpoDGO7c3ojpAiCt7tC77IyVBDAMOAFCIjIwMjQwNzI2MTgxMjE5RTBCNDM2ODlDQzM4MzAxMDcyMzJIAZABAA%22%2C%22compliance_data%22%3A%22%7B%5C%22biz_type%5C%22%3A%5C%22ad%5C%22%2C%5C%22ad%5C%22%3A%7B%5C%22download_uniform%5C%22%3A1%2C%5C%22landing_type%5C%22%3A1%2C%5C%22pricing_type%5C%22%3A9%2C%5C%22market_online_status%5C%22%3A31%2C%5C%22content_type%5C%22%3A1%2C%5C%22is_dsp%5C%22%3Afalse%2C%5C%22dsp_type%5C%22%3A0%2C%5C%22platform_version%5C%22%3A0%2C%5C%22group_type%5C%22%3A102%7D%7D%22%2C%22component_ids%22%3A%5B204835%5D%2C%22convert_component_suspend%22%3A0%2C%22convert_id%22%3A0%2C%22creative_tpl_id%22%3A0%2C%22external_action%22%3A2%2C%22fe_tpl_ids%22%3A%5B1031%5D%2C%22hyrule_atype%22%3A%5B%5D%2C%22is_pack_ng%22%3A0%2C%22is_pack_v2%22%3Atrue%2C%22landing_type%22%3A1%2C%22orit%22%3A1%2C%22pigeon_num%22%3A0%2C%22potential_tag%22%3A0%2C%22render_type%22%3A%22lynx%22%2C%22req_id%22%3A%2220240726181219E0B43689CC3830107232%22%2C%22rit%22%3A1%2C%22style_id%22%3A101344%2C%22style_ids%22%3A%5B101344%5D%7D%2C%22web_url%22%3A%22https%3A%2F%2Fwww.chengzijianzhan.com%2Ftetris%2Fpage%2F7117480059783004167%2F%3Fadid%3D1805636051446873%26creativeid%3D1805636051451008%26creativetype%3D5%26clickid%3DB.xR7TsT0uBKgmloi7s2SYIwFYhQpxwpJlrQha3RPeRFKJO1eGiaYSEXk9ZfCNe8CyXDedYAkGvNnSDbNEiD3iRatMeFVkH32V3Nul1BlIPTFM%26ad_id%3D1805636051446873%26cid%3D1805636051451008%26req_id%3D20240726181219E0B43689CC3830107232%22%2C%22web_title%22%3A%22%E8%81%94%E8%B0%83%22%2C%22intercept_flag%22%3A2%7D", "adid": "1805636051446873", "clickid": "B.ffOlmNOWtTUVBKxlEjOEPGXgFClGDnmUuCFqdH94jKUScq9GiaYSEXk9ZfCNe8CyXDedYAkGvNnSDbNEiD3iRatMeFVkH32V3Nul1BlIPTFM", "creativeid": "1805636051451008", "creativetype": "5", "aid": "13", "appId": "ttba99cc2425af5d1002", "mpVersion": "1.0.2" }, "scene": "016001", "subScene": "", "group_id": "", "extra": { "aid": "13", "appId": "ttba99cc2425af5d1002", "mpVersion": "1.0.2" }, "showFrom": 10 }
